﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace Repository.DAL
{
    public class DBProvider
    {
        private IDBFactory _factory;

        public DBProvider():
            this((IDBFactory)ClassContainer.Container.GetObject("dbFactory"))
        {
        }

        public DBProvider(IDBFactory factory)
        {
            _factory = factory;
        }

        public DbConnection CreateConnection()
        {
            DbConnection conn = _factory.CreateConnection();
            conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString;
            return conn;
        }

        public DbCommand CreateCommand()
        {
            return _factory.CreateCommand();
        }

        public string BuildParameterName(string name)
        {
            return _factory.BuildParameterName(name);
        }

        public DbParameter CreateParameter(DbCommand cmd)
        {
            return _factory.CreateParameter(cmd);
        }

        public void AddParameter(DbCommand cmd, string name, System.Data.DbType dbType, object value)
        {
            _factory.AddParameter(cmd, name, dbType, value);
        }
    }
}
